package com.fastbee.data.controller;

import com.fastbee.common.annotation.Log;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.iot.domain.Category;
import com.fastbee.iot.domain.WhhxDeviceParameter;
import com.fastbee.iot.service.IParameterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 产品分类Controller
 *
 * @author hejunlong
 * @date 2025-06-25
 */
@Api(tags = "设备参数设置")
@RestController
@RequestMapping("/iot/parameter")
public class ParameterController extends BaseController
{
    @Autowired
    private IParameterService parameterService;

    /**
     * 查询设备参数列表
     */
    @GetMapping("/list")
    @ApiOperation("设备参数列表")
    @PreAuthorize("@ss.hasPermi('iot:parameter:list')")
    public TableDataInfo list(WhhxDeviceParameter whhxDeviceParameter)
    {
        startPage();
        return getDataTable(parameterService.selectParameterList(whhxDeviceParameter));
    }

    /**
     * 获取设备参数详细信息
     */
    @ApiOperation("获取设备参数详情")
    @PreAuthorize("@ss.hasPermi('iot:parameter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(parameterService.selectParameterById(id));
    }

    /**
     * 根据参数编码获取设备参数详情
     */
    @ApiOperation("根据参数编码获取设备参数详情")
    @PreAuthorize("@ss.hasPermi('iot:parameter:repeat')")
    @GetMapping(value = "/code")
    public AjaxResult getInfoByCode(@RequestParam("code") String code)
    {
        return AjaxResult.success(parameterService.selectParameterByCode(code));
    }

    /**
     * 新增产品分类
     */
    @PreAuthorize("@ss.hasPermi('iot:parameter:add')")
    @Log(title = "设备参数设置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加设备参数")
    public AjaxResult add(@RequestBody WhhxDeviceParameter whhxDeviceParameter)
    {
        return toAjax(parameterService.insertParameter(whhxDeviceParameter));
    }

    /**
     * 修改产品分类
     */
    @PreAuthorize("@ss.hasPermi('iot:parameter:edit')")
    @Log(title = "设备参数设置", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改设备参数")
    public AjaxResult edit(@RequestBody WhhxDeviceParameter whhxDeviceParameter)
    {
        return toAjax(parameterService.updateParameter(whhxDeviceParameter));
    }

    /**
     * 删除产品分类
     */
    @PreAuthorize("@ss.hasPermi('iot:parameter:remove')")
    @Log(title = "设备参数设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    @ApiOperation("批量删除设备参数设置")
    public int remove(@PathVariable Long id)
    {
        return parameterService.deleteParameterId(id);
    }
}
